"""
家 | 数据层
"""

from models.po import FamilyHomePO
from my_typing import *
from service.base import ServiceBase
from utils.data_utils.special import ObjectIdStr


class FamilyHomeService(ServiceBase[FamilyHomePO]):
    """ 家庭 | 家 | 数据层 """

    po = FamilyHomePO
    collection_name = "family_home"
    single_field_index = [
        "id",
        "name",
        "region_id",
        "user_id",
    ]

    @classmethod
    def get_one_by_name(cls, name: str) -> FamilyHomePO | None:
        if not name:
            return None

        return cls.find_one({"name": name})

    @classmethod
    def get_many_by_user_id(cls, user_id: ObjectIdStr) -> Iterator[FamilyHomePO]:
        if not user_id:
            return iter([])

        return cls.find({"user_id": user_id})
